package com.ljc.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljc.common.ErrorCode;
import com.ljc.exception.BusinessException;
import com.ljc.mapper.UserMapper;
import com.ljc.model.entity.User;
import com.ljc.model.vo.UserDevKeyVO;
import com.ljc.model.vo.UserVO;
import com.ljc.service.InnerUserService;
import com.ljc.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService
public class InnerUserServiceImpl implements InnerUserService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private UserService userService;

    @Override
    public User getInvokeUser(String accessKey) {
        if (StringUtils.isAnyBlank(accessKey)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("accessKey", accessKey);
        return userMapper.selectOne(queryWrapper);
    }

    @Override
    public UserVO getLoginUser(String cookie) {
        return userService.getLoginUser(cookie);
    }


    @Override
    public UserDevKeyVO genKey(String userAccount) {
        return userService.genKey(userAccount);
    }

    @Override
    public boolean save(User user) {
        return userService.save(user);
    }

    @Override
    public User selectOne(String userAccount) {
        return userMapper.selectOne(new QueryWrapper<User>().eq("userAccount", userAccount));
    }


}
